<!DOCTYPE html>
<html>
    <head>
        <title>例子</title>
        <meta charset="utf-8">
    </head>

    <body>
        <div style="width:400px;margin:20px auto;text-align:center;">
            <p>常规http</p>
            <a href="http://localhost:3000/">GET</a>
            <a href="http://localhost:3000/students?id=2">GET(id)</a>
            <a href="javascript:do_post();">POST</a>
        </div>

        <div style="width:400px;margin:40px auto;text-align:center;">
            <p>restful</p>
            <a href="http://localhost:3000/members/4">GET</a>
            <a href="javascript:do_post_rest();">POST</a>
        </div>

        <script src="jquery.min.js"></script>
        <script>
            function do_post() {
                $.ajax({
                    url: 'http://localhost:3000/students?id=19',
                    method: 'post',
                    data: {
                        size: 23,
                        name: 'hello'
                    },
                    dataType: 'json',
                    success: function (data) {
                        alert(JSON.stringify(data));
                    }
                });
            }

            function do_post_rest() {
                $.ajax({
                    url: 'http://localhost:3000/members/13',
                    method: 'post',
                    data: {
                        name: '小明',
                        age: 22
                    },
                    dataType: 'json',
                    success: function (data) {
                        alert(JSON.stringify(data));
                    }
                });
            }
        </script>
    </body>
</html>